package com.hyp.controller;

import com.hyp.pojo.*;
import com.hyp.service.AppointmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j //显示日志消息
@RestController
@RequestMapping("/wx/")
public class AppointmentController {
    @Autowired
    private AppointmentService appointmentService;
//用户端
    //创建预约订单
    @PostMapping("/appointments")
    public Result addAppoint(@RequestBody Appointment appointment){
        appointmentService.addAppoint(appointment);
        return Result.success(appointment);
    }
    //按照预约状态分类显示数据
    @GetMapping("/appointlist/{userId}/{appointmentStatus}")
    public Result appointlist(@PathVariable Integer userId,@PathVariable String appointmentStatus){
        List<Appointment> appointlist = appointmentService.appointlist(userId,appointmentStatus);
        return Result.success(appointlist);
    }
  //显示某个预约订单信息
    @GetMapping("/appointlistById/{appointmentId}")
    public Result appointlistById(@PathVariable Integer appointmentId){
        Appointment appointment = appointmentService.appointlistById(appointmentId);
        return Result.success(appointment);
    }

    //取消预约
    @PutMapping("/offappoint")
    public Result offappoint(@RequestBody Appointment appointment){
        appointmentService.offappoint(appointment);
        return Result.success();
    }

    //搜索框
    @GetMapping("/search")
    public Result search( String description){
        System.out.println("搜索词："+description);
        List<Product> searchproducts = appointmentService.search(description);
        return Result.success(searchproducts);
    }

//后台端
    //显示全部预约订单
    @GetMapping("/allappointlist")
    public Result allappointlist(){
        List<AppointmentDTO> allappointlist = appointmentService.allappointlist();
        return Result.success(allappointlist);
    }

    //完成订单
    @PutMapping("/finishappoint")
    public Result finishappoint(@RequestBody Appointment appointment){
        appointmentService.finishappoint(appointment);
        return Result.success();
    }
}
